package com.by.redis.enums;

import com.by.redis.consts.ByRedisConst;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
public enum ByRedisUtilityEnum {

    COMMON(1, "公共", ByRedisConst.COMMON_STR_REDIS_TEMPLATE_NAME, ByRedisConst.COMMON_JSON_REDIS_TEMPLATE_NAME),
    LIVE(2, "直播专用", ByRedisConst.LIVE_STR_REDIS_TEMPLATE_NAME, ByRedisConst.LIVE_JSON_REDIS_TEMPLATE_NAME),
    CACHE(3, "缓存", ByRedisConst.CACHE_STR_REDIS_TEMPLATE_NAME, ByRedisConst.CACHE_JSON_REDIS_TEMPLATE_NAME),
    ;

    private final Integer code;
    private final String desc;

    private final String strRedisTemplateName;

    private final String jsonRedisTemplateName;


    private static final Map<Integer, ByRedisUtilityEnum> MAP = Arrays.stream(ByRedisUtilityEnum.values())
            .collect(Collectors.toMap(ByRedisUtilityEnum::getCode, Function.identity()));

    public static ByRedisUtilityEnum resolve(Integer code){
        return MAP.get(code);
    }

}
